﻿using MvcSimplyCleverPart3.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcSimplyCleverPart3.Controllers
{
    public class AjaxController : Controller
    {
        [AddressFormFilter]
        [ValidateInput(false)]
        public ActionResult SwitchCountry(AddressViewModel address)
        {
            if (ControllerContext.IsChildAction)
            {
                // CHECK.
                // in case whole page is rendered from AddressPage1, user parent's ViewData (to propagate ModelState)
                this.ViewData = ControllerContext.ParentActionViewContext.ViewData;
            }
            else
                ModelState.Clear();


            return PartialView(address);
        }
    }
}
